package org.longIt.springdata.service.impl;

import java.util.List;
import javax.annotation.Resource;
import org.longIt.springdata.domain.Clazz;
import org.longIt.springdata.domain.Student;
import org.longIt.springdata.repository.ClazzRepository;
import org.longIt.springdata.repository.StudentRepository;
import org.longIt.springdata.service.StudentService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class StudentServiceImpl implements StudentService {

	@Resource
	private StudentRepository studentRepository;
	
	@Resource
	private ClazzRepository clazzRepository;
	
	@Override
	public List<Student> findStudentsByClazzName(String clazzName) {
		
		return studentRepository.queryClazzName(clazzName);
	}

	@Override
	public void saveAllClazz(List<Clazz> clazzs) {
		clazzRepository.saveAll(clazzs);
		
	}

	@Override
	public void saveAllStus(List<Student> students) {
		studentRepository.saveAll(students);
		
	}

	@Override
	public List<Student> findStudentsByClazzNameAndSex(String clazzName, String sex) {
		
		return studentRepository.querySexAndClazzName(clazzName, sex);
	}

	// 通过@Query进行DML操作，需要加事务处理 
	@Transactional
	@Override
	public void deleteByName(String name) {
		System.out.println("name = " + name);
		studentRepository.removeByName(name);
		
	}

}
